package com.example.myapp;

import inc.Data;
import inc.Member;
import inc.Trip;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class AddMembers extends Activity{
	
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add_members);
	
		Bundle bundle = getIntent().getExtras();
		final Data data = (Data) bundle.getParcelable("data");
		final String trip_name = (String) bundle.get("trip name").toString();
		final ArrayList<Member> members = new ArrayList<Member>();
		
		final EditText member_name_text = (EditText) findViewById(R.id.trip_name_text);
		
		Button button_add_member = (Button) findViewById(R.id.add_member_button);
		button_add_member.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Member m = new Member(member_name_text.getText().toString());
				members.add(m);
				member_name_text.setText("");
				}
		});
		
		Button button_Create_trip = (Button) findViewById(R.id.Create_button);
		button_Create_trip.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Trip created_trip = new Trip(trip_name, members, 0);
				data.addTrip(created_trip);
				Intent intent = new Intent(getApplicationContext(), MainActivity.class);
				intent.putExtra("data", data);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent);
				}
		});
	}	
}

